home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / thor / insertit.thor < prev    next >
Text File  |  1996-11-10  |  14KB  |  508 lines

  1. /* $VER: InsertIt V1.03 (25.10.96) Shaun Downend.
  2.  *          <shaund@amiganut.demon.co.uk>
  3.  *        Insert useful information into a message.
  4.  *
  5.  * Supported editors:-
  6.  * FSE (Thor internal editor), GoldED, TurboText, and CygnusED.
  7.  * Clipboard support for other editors.
  8.  *
  9.  * This script should be launched from your text editor!
  10.  */
  11.  
  12. /****************************************************/
  13. /* Edit the configuration below to suit your system */
  14. /****************************************************/
  15.  
  16. htmlhotlist = 'AWeb:AWeb.hotlist'    /* path and filename of browser hotlist */
  17.  
  18. hotlistmode = 'A'   /* H = HTML hotlist (IBrowse, Voyager)  *
  19.                      * A = AWeb hotlist (v1.2b, v1.4, v2.0) */
  20.  
  21. mode = 'A'  /* Mode of operation (I/C/A)  *
  22.              * I = Insert into message    *
  23.              * C = Save to Clipboard ONLY *
  24.              * A = Ask user               */
  25.  
  26. cutmarkers = 1          /* Option to insert "cut here" markers. 1 = enable, 0 = disable
  27.                          * The marker begin and end strings are set below.
  28.                          */
  29.  
  30. cutstart = '----8<----'
  31. cutend   = '---->8----'
  32.  
  33. /****************************************************/
  34. /* end of configuration - do not edit below here    */
  35. /****************************************************/
  36.  
  37. options results
  38.  
  39. scriptver = subword(sourceline(1), 4,1)
  40.  
  41. /*!~ "check for arexx ports" */
  42.  
  43. editorport = ''
  44.  
  45. /* List of supported editors and arexx commands to insert text - expandable */
  46.  
  47. rp.count = 4
  48.  
  49. rp.name.1 = 'GOLDED'
  50. rp.text.1 = 'CLIP PASTE'
  51. rp.name.2 = 'THOR_FSE'
  52. rp.text.2 = 'PASTECLIP'
  53. rp.name.3 = 'rexx_ced'
  54. rp.text.3 = 'PASTE'
  55. rp.name.4 = 'TURBOTEXT'
  56. rp.text.4 = 'PASTECLIP'
  57.  
  58. /* Check for existance of an editor */
  59.  
  60. do i = 1 to rp.count
  61.     if(substr(address(),1,length(rp.name.i)) = rp.name.i) then
  62.     do
  63.         editorport = address()
  64.         addtext = rp.text.i
  65.     end
  66. end
  67.  
  68. if editorport = '' & (upper(mode) = 'I' | upper(mode) = 'A') then
  69. do
  70.     say 'This script has to be run from your editor.'
  71.     say 'GoldED, FSE (Thor''s internal editor), TurboText, and CygnusED are currently supported.'
  72.     say 'To use this script with another editor set MODE = ''C'' in the script to save to clipboard.'
  73.     say 'You will then have to select paste from clipboard manually.'
  74.     exit
  75. end
  76.  
  77. /* Check for existance of Thor */
  78.  
  79. p=' '||address()||' '||show('P',,)
  80. if pos(' THOR.',p)>0 then
  81. thorport=word(substr(p,pos(' THOR.',p)+1),1)
  82. else
  83. do
  84.     say ('Thor has to be running to use this script!')
  85.     exit(10)
  86. end
  87. /*~!*/
  88. /*!~ "main code" */
  89.  
  90. address(thorport)
  91.  
  92. call insertchoice /* insert url, fileinfo, message info, or file info? */
  93.  
  94. parse var result action searchfor
  95.  
  96. searchfor = upper(strip(searchfor))
  97. if searchfor = '' then exit(5)
  98.  
  99. if action = 1 then /* process hotlist */
  100. do
  101.     if ~exists(htmlhotlist) then
  102.     do
  103.         call errmsg(htmlhotlist' does not exist.\nPlease configure htmlhotlist to match a hotlist on your hd.',0)
  104.         exit(10)
  105.     end
  106.     else
  107.     do
  108.         call searchhotlist
  109.         if LIST.COUNT = 0 then call errmsg('No matching URL''s found.',0)
  110.         call selmatches
  111.         call restorehl
  112.     end
  113. end
  114.  
  115. if action = 2 then /* process filedatabase */
  116. do
  117.     if ~show('p', 'BBSREAD') then
  118.     do
  119.         address command
  120.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  121.         "WaitForPort BBSREAD"
  122.     end
  123.     call selbbs
  124.     call filesearch
  125.     if LIST.COUNT = 0 then call errmsg('No matching files found.',0)
  126.     call selmatches
  127. end
  128.  
  129. if action = 3 then /* process message */
  130. do
  131.     call savemsg
  132.     call scanfile(tempfile)
  133.     if LIST.COUNT = 0 then call errmsg('Insert message aborted.',0)
  134.     if LIST.COUNT ~= 0 then address command 'c:delete >NIL: 'tempfile
  135.     call selmatches
  136. end
  137.  
  138. if action = 4 then /* process file */
  139. do
  140.     call selfile
  141.     call scanfile(tempfile)
  142.     if LIST.COUNT = 0 then call errmsg('Insert file aborted.',0)
  143.     call selmatches
  144. end
  145.  
  146. call insert /* insert/clip text */
  147.  
  148. exit(0)
  149. /*~!*/
  150. /*!~ "Insert what?" */
  151. insertchoice: procedure
  152.  
  153. 'requestnotify text "InsertIt options..." bt "_URL|_FileInfo|_Message|File|_Cancel"'
  154. if result = 0 then exit(0)
  155. if result = 1 then /* select url to search for */
  156. do
  157.     call searchstring('InsertURL','Insert search string...\n\nIt can be a keyword in the URL or in \nthe name of the web page.')
  158.     parse var result searchfor
  159.     return 1 searchfor
  160. end
  161. if result = 2 then /* select file to search for */
  162. do
  163.     call searchstring('InsertFileInfo','Insert search string...\n\nIt can be a keyword from an Aminet file.')
  164.     parse var result searchfor
  165.     return 2 searchfor
  166. end
  167. if result = 3 then return 3 'nosearch' /* no search - message selected */
  168. if result = 4 then return 4 'nosearch' /* no search - file selected */
  169. return
  170. /*~!*/
  171. /*!~ "Allow user to enter search string" */
  172. searchstring: procedure
  173.  
  174. parse arg rstitle,rsbt
  175.  
  176. 'requeststring title "'rstitle'" bt "_Search|_Cancel" body "'rsbt'"'
  177. if(rc = 5) then exit
  178. else if(rc ~= 0)then call errmsg(THOR.LASTERROR,10)
  179. return result
  180. /*~!*/
  181. /*!~ "Search the hotlist for user defined string" */
  182.  
  183. searchhotlist:
  184.  
  185. drop SLIST.
  186. drop LIST.
  187. m = 0
  188.  
  189. if(~OPEN(hl,htmlhotlist,'R')) then call errmsg('Unable to open hotlist!',10)
  190. filelength = SEEK(hl,0,'E')
  191. call oprog('Scanning hotlist for 'searchfor,filelength,'Looking for...'searchfor'...',abort)
  192. call seek(hl, 0,'B')
  193.  
  194. do until currpos = filelength
  195.     prevline = line
  196.     line = readln(hl)
  197.     currpos = seek(hl, 0)
  198.     if (currpos // 10 = 0) then call uprog(window,currpos,'Found 'm' match(es)')
  199.     if result = 5 then call errmsg('InsertIt URL search aborted.',0)
  200.  
  201.     if pos(searchfor,upper(line)) ~= 0 then
  202.  
  203.     do
  204.  
  205.         if upper(hotlistmode) = 'H' then /* html hotlist search */
  206.         do
  207.             m = m + 1
  208.             parse var line '<LI><A HREF="' url '"' ibf '>' name '</A>'
  209.             SLIST.m = strip(name)' :- 'strip(url)
  210.             LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
  211.             if strip(LIST.m) = ':-' then m = m - 1
  212.         end
  213.  
  214.         if upper(hotlistmode) = 'A' then /* AWeb hotlist search */
  215.         do
  216.             parse var line url
  217.             if pos('TP://',upper(url)) > 0 then
  218.             do                          /* search string found in URL */
  219.                 m = m + 1
  220.                 line = readln(hl)
  221.                 currpos = seek(hl, 0)
  222.                 call uprog(window,currpos,'Found 'm' match(es)')
  223.                 if result = 5 then call errmsg('InsertIt URL search aborted.',0)
  224.                 parse var line name
  225.                 SLIST.m = strip(name)' :- 'strip(url)
  226.                 LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
  227.                 if strip(LIST.m) = ':-' then m = m - 1
  228.             end
  229.             else
  230.             do                          /* search string found in page name */
  231.                 name = url
  232.                 line = prevline
  233.                 parse var line url
  234.                 if pos('TP://',upper(url)) > 0 then
  235.                 do
  236.                     m = m + 1
  237.                     call uprog(window,currpos,'Found 'm' match(es)')
  238.                     if result = 5 then call errmsg('InsertIt URL search aborted.',0)
  239.                     SLIST.m = strip(name)' :- 'strip(url)
  240.                     LIST.m = left(strip(name),20,' ')' :- 'strip(url) /* truncate page name for listview */
  241.                     if strip(LIST.m) = ':-' then m = m - 1
  242.                 end
  243.             end
  244.         end
  245.     end
  246. end
  247. call cprog(window)
  248. LIST.COUNT = m
  249. SLIST.COUNT = LIST.COUNT
  250. return
  251. /*~!*/
  252. /*!~ "Restore hotlist" */
  253. restorehl:
  254.  
  255. do i = 1 to SELECTED.COUNT
  256.     parse var SELECTED.i sname ' :- ' surl
  257.     do h = 1 to SLIST.COUNT
  258.         parse var SLIST.h lname ' :- ' lurl
  259.         if surl = lurl then SELECTED.i = SLIST.h /* restore full page name to insert in editor or clipboard */
  260.     end
  261. end
  262. return
  263. /*~!*/
  264. /*!~ "Search for files in database" */
  265.  
  266. filesearch:
  267.  
  268. drop LIST.
  269.  
  270. c = 0
  271.  
  272. call oprog('Searching for 'searchfor,1,'Scanning filedatabase...')
  273. address (bbsread)
  274. 'searchbrfile bbsname "'bbs'" stem' SRESULT 'search "'searchfor'" keyword'
  275.  
  276. if(result > 0) then
  277. do                  /* matches have been found in the filedatabase */
  278.     call uprog(window,1,'Completed')
  279.     if result = 5 then call errmsg('InsertIt File info search aborted.',0)
  280.     do w = 1 to 400 /* delay */
  281.     end
  282.     call cprog(window)
  283.     call oprog('Searching for 'searchfor,1,'Searching file areas...',abort)
  284.     call uprog(window,0,'Searching  'SRESULT.FILEAREA.f' ('f'/'SRESULT.FILEAREA.COUNT')   Found 'c' file(s).',SRESULT.FILEAREA.COUNT)
  285.     if result = 5 then call errmsg('InsertIt File info search aborted.',0)
  286.     do f=1 to SRESULT.FILEAREA.COUNT    /* process fileareas */
  287.         do i=1 to SRESULT.FILE.f.COUNT  /* process files in each filearea */
  288.             address(bbsread)
  289.             call showfiledata('"'bbs'"', '"'SRESULT.FILEAREA.f'"', SRESULT.FILE.f.i) /* get file info */
  290.             call uprog(window,f,'Searching  'SRESULT.FILEAREA.f' ('f'/'SRESULT.FILEAREA.COUNT')   Found 'c' file(s).')
  291.             if result = 5 then call errmsg('InsertIt File Info search aborted.',0)
  292.         end
  293.     end
  294. LIST.COUNT = c
  295. call cprog(window)
  296. end
  297. else
  298. do
  299.     LIST.COUNT = 0 /* no matching files have been found */
  300.     call uprog(window,1,'Completed')
  301.     if result = 5 then call errmsg('InsertIt File Info search aborted.',0)
  302.     do w = 1 to 400 /* delay */
  303.     end
  304.     call cprog(window)
  305. end
  306. return
  307.  
  308. /*!~ Procedure to show the data about a file */
  309.  
  310. showfiledata: procedure expose LIST. c
  311.  
  312. parse arg bbs,farea,filenr
  313.  
  314. FDF_DELETED = '00000001'x
  315.  
  316. drop FILE.
  317.  
  318. address (bbsread)
  319. 'readbrfile' bbs farea filenr 'tagsstem' FILE 'datastem' DATA
  320.  
  321. nextfile = result
  322.  
  323. if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then /* file is not deleted */
  324. do
  325.     if(symbol("FILE.SIZE") = "VAR") then fsize = FILE.SIZE
  326.     else size = "Unkn"
  327.  
  328.     if(symbol("FILE.DESCRIPTION.COUNT") = "VAR") then descr = FILE.DESCRIPTION.1
  329.     else descr = "NONE"
  330.  
  331.     c = c + 1
  332.     /* format file information in Aminet RECENT format */
  333.     LIST.c = left(FILE.NAME,18) || ' ' || left(strip(farea,B,'"'),10,' ')  || ' ' || right(fsize,7) || ' ' || left(descr,39)
  334. end
  335. else
  336. do
  337.     c = c + 1
  338.     LIST.c 'File is deleted.'
  339. end
  340.  
  341. return
  342. /*~!*/
  343.  
  344. /*~!*/
  345. /*!~ "Save message and prepare for listview" */
  346. savemsg:
  347.  
  348. tempfile = 't:InsertIt.'time(s)
  349.  
  350. 'savemessage current overwrite noheader noansi filename' tempfile /* save current msg in main window */
  351. if rc = 5 then call errmsg('Message is deleted',0)
  352. if rc ~= 0 then call errmsg('SAVEMESSAGE failed: 'THOR.LASTERROR,10)
  353.  
  354. return
  355. /*~!*/
  356. /*!~ "Select file" */
  357. selfile:
  358.  
  359. 'requestfile title "Select a file:" id "ram:" fp pat "#?"'
  360. if(rc=5) then call errmsg('Aborted file search',0)
  361. if(rc~=0) then call errormsg('REQUESTFILE failed: 'THOR.LASTERROR,10)
  362.  
  363. tempfile = result
  364.  
  365. return
  366. /*~!*/
  367. /*!~ "Scan file" */
  368. scanfile:
  369.  
  370. parse arg tempfile
  371.  
  372. drop LIST.
  373. m = 0
  374. if(~open(msg,tempfile,'R')) then call errmsg('Unable to open tempfile!',10)
  375. filelength = SEEK(msg,0,'E')
  376. m = m + 1
  377. call oprog('Scanning file...',filelength,'Processing line 'm'...',abort)
  378. call seek(msg, 0,'B')
  379.  
  380. do until currpos = filelength /* read file into stem for listview */
  381.     line = readln(msg)
  382.     currpos = seek(msg, 0)
  383.     LIST.m = line
  384.     if (m // 10 = 0) then call uprog(window,currpos,'Processing line 'm'...')
  385.     if result = 5 then call errmsg('InsertIt message/file search aborted.',0)
  386.     m = m + 1
  387. end
  388. call cprog(window)
  389. call close(msg)
  390. LIST.COUNT = m
  391.  
  392. return
  393. /*~!*/
  394. /*!~ "Display matched entries" */
  395.  
  396. selmatches:
  397. drop SELECTED.
  398. SELECTED.COUNT = 0
  399. address(thorport)
  400. 'requestlist instem' LIST 'outstem' SELECTED 'title "Select entries to insert into message:" dragselect'
  401. if(rc = 5) then exit(0)
  402. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  403. return
  404. /*~!*/
  405. /*!~ "Insert selected entries into editor" */
  406.  
  407. insert:
  408. lf = '0a'x
  409.  
  410. if upper(mode) = 'A' then
  411. do
  412.     address(thorport)
  413.     'requestnotify text "InsertIt options..." bt "_Insert|_Save to Clipboard only|_Cancel"'
  414.     if result = 0 then exit(0)
  415.     if result = 1 then mode = 'I'
  416.     if result = 2 then mode = 'C'
  417. end
  418.  
  419. cliptext = ''
  420. cliptemp = 't:cliptemp'
  421. if(~open(ctemp,cliptemp,'W')) then call errmsg('Unable to open clipfile!',10)
  422. if cutmarkers = 1 then call writeln(ctemp,cutstart)
  423. do i = 1 to SELECTED.COUNT
  424.     call writeln(ctemp,SELECTED.i) /* write info to file to put into clipboard */
  425. end
  426. if cutmarkers = 1 then call writeln(ctemp,cutend)
  427. call close(ctemp)
  428. address(thorport)
  429. 'putclip file' cliptemp
  430. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  431. address command 'c:delete >NIL: 'cliptemp
  432. if(rc~=0) then call errmsg('Unable to delete cliptemp!',10)
  433.  
  434.  
  435. if upper(mode) = 'I' then
  436. do
  437.     if editorport ~= '' then
  438.     do
  439.         address(editorport)
  440.         addtext
  441.     end
  442. end
  443.  
  444. return
  445. /*~!*/
  446. /*!~ "Display error message and exit" */
  447.  
  448. errmsg:
  449. parse arg msgtxt,failcode
  450. address(thorport)
  451. 'requestnotify "'msgtxt'"' '" _OK "'
  452. if(rc = 30) then say THOR.LASTERROR
  453. exit(failcode)
  454. return
  455. /*~!*/
  456. /*!~ "Select BBS" */
  457.  
  458. selbbs:
  459. address (bbsread)
  460. 'getbbslist stem' BBSLIST
  461. if(rc ~= 0) then call errmsg(BBSREAD.LASTERROR,10)
  462. if BBSLIST.count = 1 then
  463. do
  464.     bbs = BBSLIST.1
  465.     return
  466. end
  467. address(thorport)
  468. 'thortofront'
  469.  
  470. 'requestlist instem' BBSLIST 'title "Select BBS:" SIZEGADGET'
  471. if(rc ~= 0) then exit
  472. else bbs = result
  473. return
  474. /*~!*/
  475. /*!~ "Open progress indicator" */
  476. oprog:
  477. parse arg ptitle,ptotal,ptxt,at
  478. if at ~= '' then at = 'at "_Abort"'
  479. address(thorport)
  480. 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"' at
  481. if(rc ~= 0) then call errmsg('OPENPROGRESS failed: 'THOR.LASTERROR,10)
  482. else window = result
  483. return
  484. /*~!*/
  485. /*!~ "Update progress indicator" */
  486. uprog:
  487. parse arg pwindow,pcurrent,ptxt,ptotal
  488. if ptotal = '' then ptotal = ''
  489. else ptotal = 'total 'ptotal
  490. address(thorport)
  491. 'updateprogress req' pwindow 'current' pcurrent ptotal 'pt "'ptxt'"'
  492. if(rc=5) then
  493. do
  494.     call cprog(pwindow)
  495.     return(5)
  496. end
  497. if(rc=30) then call errmsg('UPDATEPROGRESS failed: 'THOR.LASTERROR,10)
  498. return(0)
  499. /*~!*/
  500. /*!~ "Close Progress indicator" */
  501. cprog:
  502. parse arg pwindow
  503. address(thorport)
  504. 'closeprogress req' pwindow
  505. return
  506. /*~!*/
  507.  
  508.